package service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import entity.Candidate;
import util.DateUtil;
import dao.UsersDao;
import entity.Users;


public class UsersService {
	UsersDao dao = new UsersDao();
	//验证登录
	public List<String> check(Users user){
//		if(dao.exists(user)){
//			return true;
//		}
//		return false;

		return dao.exists(user);
	}
	//添加用户
	public boolean addUser(Users user){
		if(!dao.existsIdCard(user)&&!user.getIdCard().equals("")&&!user.getPassword().equals("")){
		  dao.addUsers(user);
		  System.out.println("添加人员成功");
		  return true;
		}
		return false;
	}
	//显示所有用户
	public List<Users> listUser(){
		List<Users> list=dao.listUser();

		System.out.println("列举成功");
		return list;

	}
	//删除用户信息
	public void deleteUser(Users users){

		users.setIsLock(Byte.parseByte(1 + ""));;
		dao.deleteUsers(users);
		System.out.println("删除成功");
	}

	public Users searchUserById(Long id){
		Users users = dao.loadUsers(id);
		if(users != null){
			return users;
		}
		else{
			return null;
		}
	}

	//更新用户信息
	public void updateUser(Users users){
		dao.update(users);
		System.out.print("更新用户"+users.getUsername()+"成功");
	}

	public boolean addCandidate(Candidate candidate){
		dao.dao_addCandidate(candidate);
		return true;
	}

	public List<Candidate> listCandidate(){
		List<Candidate> list=dao.listCandidate();

		return list;

	}

	public void updateCandidate(Candidate candidate){
		dao.updateCandidate(candidate);
	}
}
